Page({
  goLogin() {
    wx.navigateTo({
      url: '/pages/login/index',
    })
  },
  onShow() {
    if(!getApp().token)return
    if(getApp().userProfile.nickName){
      this.setData({
        ...getApp().userProfile
      })
    } else {
      // 没有
      this.getUserProfile()
    }
  },
  async getUserProfile() {
    let res = await wx.http.get('/userInfo')
    // console.log(res)
    this.setData({ ...res })
    // 更新到App里面去
    getApp().userProfile = {
      nickName: res.nickName,
      avatar: res.avatar
    }
  },
})
